package com.qxmly.fm.adapters;

import android.content.Context;
import android.graphics.Color;
import android.view.View;

import com.qxmly.fm.R;

import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

/**
 * Q
 * Date:2021/11/21$
 **/
public class IndicatorAdapter extends CommonNavigatorAdapter {

    private final String[] mTitles;
    private OnIndicatorTabClickListener mOnTabClickListener;

    public IndicatorAdapter(Context context){
        mTitles = context.getResources().getStringArray(R.array.indicator_name);
    }

    @Override
    public int getCount() {
        if(mTitles!=null){
            return mTitles.length;
        }
        return 0;

    }

    @Override
    public IPagerTitleView getTitleView(Context context, final int index) {
        SimplePagerTitleView simplePagerTitleView = new SimplePagerTitleView(context);
        simplePagerTitleView.setText(mTitles[index]);
        simplePagerTitleView.setNormalColor(Color.parseColor("#c8e6c9"));
        simplePagerTitleView.setSelectedColor(Color.WHITE);
        simplePagerTitleView.setTextSize(20);
        simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mOnTabClickListener !=null){
                    mOnTabClickListener.onTabClick(index);
                }
               //mViewPager.setCurrentItem(index);
            }
        });
        return simplePagerTitleView;
    }

    @Override
    public IPagerIndicator getIndicator(Context context) {
        LinePagerIndicator indicator = new LinePagerIndicator(context);
        indicator.setMode(LinePagerIndicator.MODE_EXACTLY);
        indicator.setYOffset(UIUtil.dip2px(context, 3));
        indicator.setColors(Color.parseColor("#ffffff"));
        return indicator;
    }
    public void setOnIndicatorTabClickListener(OnIndicatorTabClickListener listener){
        this.mOnTabClickListener= listener;
    }
    public interface OnIndicatorTabClickListener{
        void onTabClick(int index);
    }
}
